package org.rsbot.gui;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.io.File;
import java.net.MalformedURLException;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;
import javax.swing.border.EmptyBorder;
import org.rsbot.gui.actions.AccountCmd1;

import org.rsbot.gui.actions.GoToCmd1;
import org.rsbot.gui.actions.GoToFaceCmd1;
import org.rsbot.gui.actions.GoToProjectCmd1;
import org.rsbot.gui.actions.GoToTwitterCmd1;
import org.rsbot.gui.actions.GoToWikiCmd1;
import org.rsbot.gui.actions.ShotCmd1;
import org.rsbot.gui.actions.ShotUnCmd1;
import org.rsbot.util.GlobalConfiguration;

public class ToolPanel1 extends JToolBar {

    private static final long serialVersionUID = 906510024455580931L;
    final public ConsolePanel frame;

    /**
     * This is the default constructor
     */
    public ToolPanel1(ConsolePanel frame) {
        super();
        this.frame = frame;
        this.setFloatable(false);
        JButton AccountsButton = new JButton();
        try {
            final Image i = (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.RUNNING_FROM_JAR ? ToolPanel1.class.getResource(GlobalConfiguration.Paths.Resources.ACCOUNT) : new File(GlobalConfiguration.Paths.ACCOUNT).toURI().toURL()));
            AccountsButton = getDefaultButton(new AccountCmd1(frame), "", "Show Account Management Window", i);
        } catch (MalformedURLException ignored) {
        }
        this.add(AccountsButton);
        JButton ShotButton = new JButton();
        try {
            final Image i = (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.RUNNING_FROM_JAR ? ToolPanel1.class.getResource(GlobalConfiguration.Paths.Resources.SHOT_DO) : new File(GlobalConfiguration.Paths.SHOT_DO).toURI().toURL()));
            ShotButton = getDefaultButton(new ShotCmd1(frame), "", "Screenshot With Account Name Blocked", i);
        } catch (MalformedURLException ignored) {
        }
        this.add(ShotButton);
        JButton ShotUnButton = new JButton();
        try {
            final Image i = (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.RUNNING_FROM_JAR ? ToolPanel1.class.getResource(GlobalConfiguration.Paths.Resources.SHOT_UN_DO) : new File(GlobalConfiguration.Paths.SHOT_UN_DO).toURI().toURL()));
            ShotUnButton = getDefaultButton(new ShotUnCmd1(frame), "", "Screenshot With Account Name UnBlocked", i);
        } catch (MalformedURLException ignored) {
        }
        this.add(ShotUnButton);
        JButton homeButton = new JButton();
        try {
            final Image i = (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.RUNNING_FROM_JAR ? ToolPanel1.class.getResource(GlobalConfiguration.Paths.Resources.HOME_ICON) : new File(GlobalConfiguration.Paths.HOME_ICON).toURI().toURL()));
            homeButton = getDefaultButton(new GoToCmd1(frame), "", "Visit runedev-infinity.org", i);
        } catch (MalformedURLException ignored) {
        }
        this.add(homeButton);
        JButton wikiButton = new JButton();
        try {
            final Image i = (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.RUNNING_FROM_JAR ? ToolPanel1.class.getResource(GlobalConfiguration.Paths.Resources.WIKI) : new File(GlobalConfiguration.Paths.WIKI).toURI().toURL()));
            wikiButton = getDefaultButton(new GoToWikiCmd1(frame), "", "Visit runedev Wiki", i);
        } catch (MalformedURLException ignored) {
        }
        this.add(wikiButton);
        JButton faceButton = new JButton();
        try {
            final Image i = (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.RUNNING_FROM_JAR ? ToolPanel1.class.getResource(GlobalConfiguration.Paths.Resources.FACE) : new File(GlobalConfiguration.Paths.FACE).toURI().toURL()));
            faceButton = getDefaultButton(new GoToFaceCmd1(frame), "", "Visit runedev Facebook", i);
        } catch (MalformedURLException ignored) {
        }
        this.add(faceButton);
        JButton twitterButton = new JButton();
        try {
            final Image i = (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.RUNNING_FROM_JAR ? ToolPanel1.class.getResource(GlobalConfiguration.Paths.Resources.TWIT) : new File(GlobalConfiguration.Paths.TWIT).toURI().toURL()));
            twitterButton = getDefaultButton(new GoToTwitterCmd1(frame), "", "Visit runedev Twitter", i);
        } catch (MalformedURLException ignored) {
        }
        this.add(twitterButton);
        JButton projectButton = new JButton();
        try {
            final Image i = (Toolkit.getDefaultToolkit().getImage(GlobalConfiguration.RUNNING_FROM_JAR ? ToolPanel1.class.getResource(GlobalConfiguration.Paths.Resources.WEB_SMALL) : new File(GlobalConfiguration.Paths.WEB_SMALL).toURI().toURL()));
            projectButton = getDefaultButton(new GoToProjectCmd1(frame), "", "Visit runedev Project", i);
        } catch (MalformedURLException ignored) {
        }
        this.add(projectButton);
    }

    private JButton getDefaultButton(Action a, String txt, String tip, Image i) {
        JButton button = new JButton(a);
        button.setText(txt);
        button.setToolTipText(tip);
        button.setIcon(new ImageIcon(i));
        button.setFocusable(false);
        button.setMargin(new Insets(1, 0, 1, 0));
        button.setPreferredSize(new Dimension(28, 28));
        button.setMaximumSize(new Dimension(28, 28));
        button.setBorder(new EmptyBorder(0, 0, 0, 0));
        button.setFont(new Font("Futura Md BT", 0, 10));

        return button;
    }
}
